﻿using System;

namespace EmbeddedSharp.Core.Function.String
{
    public class RemoveStringNode : FuncNode
    {
        public RemoveStringNode()
            : base()
        {
            base.Value = "removeStr";
        }

        public override object Evaluate()
        {
            int length = Parameters.Count;
            if (length < 3)
            {
                throw new ArgumentException(
                    "usage: removeStr(expr, from, to)");
            }

            string expr = Parameters[length-1].Evaluate().ToString();
            int from = Convert.ToInt32(
                Parameters[length - 2].Evaluate());
            int to = Convert.ToInt32(
                Parameters[length - 3].Evaluate());

            return expr.Remove(from, to);
        }
    }
}
